import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_methods.dart';
import 'package:xindong/routes/call/view/xindong_call_rtc_video_small_view.dart';
import 'package:xindong/widgets/container/xindong_drag_container.dart';

// 悬浮  语音通话最小化
class XinDongCallMiniVideoDialog {
  // ======== 单例
  // 工厂方法构造函数
  factory XinDongCallMiniVideoDialog() => _getInstance();

  // instance的getter方法，singletonManager.instance获取对象
  static XinDongCallMiniVideoDialog get instance => _getInstance();

  // 静态变量_instance，存储唯一对象
  static XinDongCallMiniVideoDialog? _instance;

  // 获取对象
  static XinDongCallMiniVideoDialog _getInstance() {
    _instance ??= XinDongCallMiniVideoDialog._internal();
    return _instance!;
  }

  // 私有的自定义命名式构造方法，通过它实现一个类;
  // 子类不能继承internal
  // 不是关键字，可定义其他名字
  XinDongCallMiniVideoDialog._internal() {
    //初始化(设置一些默认的)...
  }

  // 唯一标识
  final String tag = "kTagCallMiniVideo";

  // 是否显示提示最小化点击
  final isShowClick = RxBool(false);

  // 延时隐藏
  void delayedHideButton() {
    if (isShowClick.value) {
      return;
    }
    isShowClick.value = true;
    Future.delayed(const Duration(seconds: 3), () {
      isShowClick.value = false;
    });
  }

  Future<dynamic> show() async {
    return await SmartDialog.show(
      tag: tag,
      // 点击返回不隐藏
      permanent: true,
      // 点击不隐藏
      clickMaskDismiss: false,
      // 不显示动画
      useAnimation: false,
      bindPage: false,
      // 背景色
      maskColor: Colors.transparent,
      // 点击事件将穿透遮罩
      usePenetrate: true,
      builder: (BuildContext context) {
        return const XinDongDragContainer(
          width: 100,
          height: 130,
          child: XinDongCallRTCVideoSmallView(),
        );
      },
    );
  }

  void hide() {
    try {
      SmartDialog.dismiss(status: SmartStatus.custom, tag: tag, force: true);
    } catch (error) {
      mCatchPrint(error);
    }
  }
}
